package cn.clwxy.gdz.dao;

import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import cn.clwxy.gdz.entity.AdminArticle;
import cn.clwxy.gdz.util.BaseDao;

public class AdminArticleDaoimp extends BaseDao implements AdminArticleDao{

	@Override
	public List<AdminArticle> getArticles(Integer pageNo,AdminArticle article) {
		String sql="select id, title,content,author,updateTime from article where id like CONCAT('%','','%') and title LIKE \n" +
				"CONCAT('%','','%') and content LIKE CONCAT('%','','%') and updateTime LIKE\n" +
				"CONCAT('%','','%') order by updateTime desc limit ?,15 ";
		return super.queryList(sql, new BeanListHandler<AdminArticle>(AdminArticle.class),article.getId(),article.getTitle(),article.getContent(),article.getAuthor(),article.getUpdateTime(), (pageNo-1)*15);
	}

	@Override
	public int updateArticle(AdminArticle article) {
		String sql="update article set title=? ,content=? where id=?";
		
		return super.update(sql, article.getTitle(),article.getContent(),article.getId());
	}

	@Override
	public int addArticle(AdminArticle article) {
		String sql="insert into article ( title,content,updateTime) values(?,?,?)";
		return super.update(sql, article.getTitle(),article.getContent(),article.getUpdateTime());
	}

	@Override
	public Long getColumns(AdminArticle article) {
		String sql="select count(id) from article where id like CONCAT('%',?,'%') and title LIKE \n" +
				"CONCAT('%',?,'%') and content LIKE CONCAT('%',?,'%') and updateTime LIKE\n" +
				"CONCAT('%',?,'%')";
		return super.queryColumn(sql, new ScalarHandler(), article.getId(),article.getTitle(),article.getContent(),article.getUpdateTime());
	}

	
}
